package multithread;

import javax.sound.midi.Soundbank;

/**
 * @Author: zhangrongqing
 * @Date: 2019/12/19 10:35
 */
public class VolatileDemo {
    public volatile int num = 0;

    public void count(){
        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    num++;
                    System.out.println(Thread.currentThread().getName() + ":" + num);
                }
            }).start();
        }
    }

    public static void main(String[] args) {
        new VolatileDemo().count();
    }
}
